package com.example.zhuyu.basemvp.http;

import javax.inject.Inject;

import retrofit2.Retrofit;

import static com.example.zhuyu.basemvp.utils.Util.checkNullException;

/**
 * @author zhuyu
 */
public final class RetrofitManager implements IRetrofitManager {


    /**
     * 超时时长
     */
    private static final long TIMEOUT = 10;

    @Inject
    Retrofit mRetrofit;

    @Inject
    public RetrofitManager() {

    }

 /*   *//**
     * Retrofit是基于OkHttpClient的，可以创建一个OkHttpClient进行一些配置
     *//*
    private static OkHttpClient httpClient = new OkHttpClient.Builder()
            // 添加通用的Header
            .addNetworkInterceptor(new NetWorkInterceptor())
            *//**
             * 这里可以添加一个HttpLoggingInterceptor，因为Retrofit封装好了从Http请求到解析，
             出了bug很难找出来问题，添加HttpLoggingInterceptor拦截器方便调试接口
             *//*
            .addInterceptor(new LogInterceptor().logInterceptor())
            .connectTimeout(TIMEOUT, TimeUnit.SECONDS)
            .readTimeout(TIMEOUT, TimeUnit.SECONDS)
            .build();*/

  /*  private static RetrofitService retrofitService = new Retrofit.Builder()
            .baseUrl(BASE_URL)
            // 添加Gson转换器
            .addConverterFactory(GsonConverterFactory.create(buildGson()))
            // 添加Retrofit到RxJava的转换器
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
            .client(httpClient)
            .build()
            .create(RetrofitService.class);*/


  /*  private Retrofit getRetrofit() {

        return new Retrofit.Builder()
                .baseUrl(BASE_URL)
                .client(httpClient)
                //添加RxJava2
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                //添加Gson解析器
                .addConverterFactory(GsonConverterFactory.create(buildGson()))
                .build();
    }*/

  /*  public static RetrofitService getInstance() {
        return retrofitService;
    }*/

    @Override
    public synchronized <T> T obtainRetrofitService(Class<T> clazz) {
        checkNullException(clazz, "传入的Service为Null 请检查是否创建Service");
        return mRetrofit.create(clazz);
    }

   /* private static Gson buildGson() {
        return new GsonBuilder()
                .setDateFormat("yyyy-MM-dd hh:mm:ss")
                .serializeNulls()//支持null值
                .enableComplexMapKeySerialization()//支持Object为key的map对象,默认只支持String为key的map
                .create();
    }*/
}
